package com.bole.controller;

import com.alibaba.fastjson.JSONObject;
import com.bole.constant.ContentRedis;
import com.bole.dao.UserDao;
import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.brand.DicBrandDto;
import com.bole.dto.content.TbContentDto;
import com.bole.dto.permission.AdminDto;
import com.bole.dto.user.UserDto;
import com.bole.pojo.TbContentDo;
import com.bole.pojo.TbUserDo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("login")
@Api(value = "会员管理api")
public class LoginController {
    @Autowired
    private UserDao userDao;

    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/getUserByTelephone")
    @ApiOperation(value = "查询会员")
    @ApiImplicitParam(name = "String telephone" ,required = true,dataTypeClass = TbUserDo.class)
    public Result getUserByTelephone(@RequestParam("telephone") String telephone) {
        TbUserDo userDo = userDao.getUserByTelephone(telephone);
        if (userDo == null) {
            return Result.response(ResultEnum.FAIL);
        }
       UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userDo,userDto);
        return Result.response(ResultEnum.OK).setData(userDto);
    }


    @PostMapping("saveUserInfo")
    @ApiOperation(value = "保存")
    @ApiImplicitParam(name = "userDo",value = "手机号",required = true,dataTypeClass = TbUserDo.class)
    public void saveUserInfo(@RequestBody TbUserDo userDo) {
       TbUserDo userDo1  = userDao.save(userDo);
       UserDto userDto = new UserDto();
       BeanUtils.copyProperties(userDo1,userDto);
    }



    //查询会员信息
    @PostMapping("selectUserByTelephone")
    @ApiOperation(value = "回显")
    @ApiImplicitParam(name = "id",value = "id",required = true,dataTypeClass = Long.class)
    public UserDto toUpdate(@RequestParam("id") Long id) {
        TbUserDo userDo = userDao.findById(id).get();
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userDo,userDto);
        return userDto;
    }



        //完善会员信息
        @PostMapping("addUserInfo")
        @ApiOperation(value = "保存会员信息")
        @ApiImplicitParam(name = "carSeriesDo",value = "会员对象",required = true,dataTypeClass = TbUserDo.class)
        public void addUserInfo(@RequestBody TbUserDo userDo) {
           TbUserDo userDo1 = userDao.save(userDo);
           UserDto userDto = new UserDto();
            BeanUtils.copyProperties(userDo1,userDto);
        }




}
